#include "UploadForm.h"
#include "ui_UploadForm.h"
#include <QFileDialog>
#include "SqliteDb.h"

UploadForm::UploadForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::UploadForm)
{
    ui->setupUi(this);
}

UploadForm::~UploadForm()
{
    delete ui;
}

void UploadForm::on_btn_save_clicked()
{
    QString strResult = ui->textEdit->toPlainText();
    if(strResult.isEmpty())
    {
        return;
    }
    DB_TYPE_DATA dataMap;
    dataMap["id"] = SqliteDb::m_SqliteDb.getMaxId("data") + 1;
    dataMap["result"] = strResult;
    dataMap["name"] = ui->lineEdit->text().split("/").last();
    SqliteDb::m_SqliteDb.insertRow("data", dataMap);
}

void UploadForm::on_btn_up_clicked()
{
    QString filePath = QFileDialog::getOpenFileName(this, "打开", "./Resource/Topic", "img(*png *.jpg)");
    if(filePath.isEmpty())
    {
        return;
    }

    ui->lineEdit->setText(filePath);
    QPixmap pixmap(filePath);
    pixmap = pixmap.scaled(1200, 580);
    ui->label->setPixmap(pixmap);
}
